#NO_APP
	.text
	.align	2
	.globl	_start
	.type	_start, @function
_start:
    #尽量备份所有寄存器
    #d0和d1会被覆盖
    #a1 寄存器为0，所以作为基址
    #合金弹头5的返回地址和不使用的内存地址

#if defined(MSLUGX)
    .equ save_address,0x100800
    .equ ret_address,0xCA254
#elif defined(MSLUG3)
    .equ save_address,0x10B000
    .equ ret_address,0x28A4C
#elif defined(MSLUG4)
    .equ save_address,0x10C000
    .equ ret_address,0x8D9A
#elif defined(MSLUG5)
    .equ save_address,0x110090
    .equ ret_address,0x49B52
#elif defined(MSLUG2)
    .equ save_address,0x106c00
    .equ ret_address,0x9F132
#elif defined(MSLUG1)
    .equ save_address,0x10E500
    .equ ret_address,0x5CC80
#endif

#if defined(MSLUG1)
    move.l #0x10e200,%a2
    move.l #0x10e212,%a1
    move.l (%a2)+,(%a1)+
    move.w (%a2)+,(%a1)+
#endif

    move.l #save_address,%a1
    move.l  %d0,0*4(%a1)
    move.l  %d1,1*4(%a1)
    move.l  %d2,2*4(%a1)
    move.l  %d3,3*4(%a1)
    move.l  %d4,4*4(%a1)
    move.l  %d5,5*4(%a1)
    move.l  %d6,6*4(%a1)
    move.l  %d7,7*4(%a1)

    move.l  %a0,8*4(%a1)
    move.l  %a1,9*4(%a1)
    move.l  %a2,10*4(%a1)
    move.l  %a3,11*4(%a1)
    move.l  %a4,12*4(%a1)
    move.l  %a5,13*4(%a1)
    move.l  %a6,14*4(%a1)
    move.l  %a7,15*4(%a1)


    sub.l   #40,%a7
    sub.l   #40,%a6
    sub.l   #40,%a5

    jsr     hack

    add.l   #40,%a7
    add.l   #40,%a6
    add.l   #40,%a5

    move.l #save_address,%a1
    move.l  0*4(%a1) ,%d0
    move.l  1*4(%a1) ,%d1
    move.l  2*4(%a1) ,%d2
    move.l  3*4(%a1) ,%d3
    move.l  4*4(%a1) ,%d4
    move.l  5*4(%a1) ,%d5
    move.l  6*4(%a1) ,%d6
    move.l  7*4(%a1) ,%d7

    move.l  8*4(%a1) ,%a0
    # move.l  9*4(%a1) ,%a1
    move.l  10*4(%a1),%a2
    move.l  11*4(%a1),%a3
    move.l  12*4(%a1),%a4
    move.l  13*4(%a1),%a5
    move.l  14*4(%a1),%a6
    move.l  15*4(%a1),%a7

#if defined(MSLUGX)
    move.b  0x435c(%a5),%d0
    move.b  0x435d(%a5),%d1
#elif defined(MSLUG3)
    move.b -0x7f6c(%a5),%d0
    move.b -0x7f6b(%a5),%d1
#elif defined(MSLUG4)
    move.b -0x1bba(%a5),%d0
    move.b -0x1bb9(%a5),%d1
#elif defined(MSLUG5)
    move.b -0x3356(%a5),%d0
    move.b -0x3355(%a5),%d1
#elif defined(MSLUG2)
    move.b -0x1ae2(%a5),%d0
    #这里没有d1，所以需要设置A4
    move.l #0X9f0DC,%a4
#endif


QUIT:
#if defined(MSLUG1)
    #这里直接返回
    move.l  #ret_address,-(%sp)
    rts
#else
    move.l  #ret_address,%a1
    jmp     (%a1)
#endif

	.globl	call
	.type	call, @function
call:


	.globl	createItem
	.type	createItem, @function
    #调用事件生成道具(或者敌人),参数1:a0为事件指针
    #可以查看 struct ITEM(hack.c)
createItem:
#if defined(MSLUGX)
    move.l  4(%sp),%a0
    move.l  #0x101414,%a6
    #jsr    0x19e82
    jsr     0x1a0a6
    rts
#elif defined(MSLUG5)
    move.l  4(%sp),%a0
    move.l  #0x100bf4,%a6
    jsr     0xe951c
    rts
#elif defined(MSLUG4)
    move.l  4(%sp),%a0
    move.l  #0x100c0c,%a6
    jsr     0x8486a
    rts
#elif defined(MSLUG3)
    move.l  4(%sp),%a0
    move.l  #0x10044c,%a6
    jsr     0x16106
    rts
#elif defined(MSLUG2)
    move.l  4(%sp),%a0
    move.l  #0x1013ec,%a6
    jsr     0x90812
    rts
#elif defined(MSLUG1)
    move.l  4(%sp),%a1
    move.l  #0x100800,%a6
    jsr     0x448A6
    rts
#endif

    .globl	save_address_ptr
save_address_ptr:
    .int save_address

